package com.novel.authorization.staff.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.novel.authorization.staff.entity.NfPerm;
import com.novel.authorization.staff.mapper.NfPermMapper;
import com.novel.authorization.staff.service.NfPermService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 权限码表
 *
 * @author 樊温军
 * @date Wed May 07 10:50:22 CST 2025
 */
@Slf4j
@Service
@AllArgsConstructor
public class NfPermServiceImpl extends ServiceImpl<NfPermMapper, NfPerm> implements NfPermService {

    @Override
    public List<NfPerm> getNfPermList(NfPerm nfPerm) {
        return baseMapper.getList(nfPerm);
    }

    @Override
    public IPage<NfPerm> getPage(Page<NfPerm> page, NfPerm nfPerm) {
        return baseMapper.getPage(page, nfPerm);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long saveOneNfPerm(NfPerm nfPerm) {
        this.saveOrUpdate(nfPerm);
        return nfPerm.getId();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delById(Long id) {
        baseMapper.delete(Wrappers.<NfPerm>query().lambda().in(NfPerm::getId, id));
    }

    @Override
    public NfPerm queryById(Long id) {
        return baseMapper.selectById(id);
    }
}
